/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telemetria.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.telemetria.HibernateUtil;
import com.telemetria.entity.endereco.Pais;

/**
 *
 * @author ARGLAS
 */
public class PaisDaoImpl implements PaisDao{

    @Override
    public List<Pais> findAllPais() {

        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List lista = session.createQuery("from Pais P order by P.deNome").list();
        t.commit();
        session.close();
        return lista;
    
    }

    @Override
    public Pais findEstadoByPK(Long pk) {
        
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        
        Query query = session.createQuery("from Pais P where P.id = :parameter1");
        query.setParameter("parameter1", pk);
        Pais pais = (Pais) query.uniqueResult(); 
        
        t.commit();
        return pais;
        
    }
    
}
